/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sender;


import com.database.entity.UserLogs;
import database.senderUtil;
import java.io.IOException;
import java.net.InetAddress;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author parent
 */
public class UserStatus {
    int UserId;
    String UserName;
    String IpAddress;
    boolean LoginStatus;
    public UserStatus() {
        try {
        InetAddress ownIP=InetAddress.getLocalHost();
        Session session = senderUtil.getSessionFactory().getCurrentSession();
        String queryString = "from UserLogs where  login_status='1' and ip_address=:ip";
        Query query = session.createQuery(queryString);  
       
        query.setString("ip", ownIP.getHostAddress());
        Object queryResult = query.uniqueResult(); 
        UserLogs userlog=(UserLogs)queryResult;
        LoginStatus=(userlog.getLoginStatus().equals("1"));
        UserId=userlog.getUserUsers().getId();
        session.getTransaction().commit(); 
        } catch (Exception ex){
            ex.printStackTrace(); 
        }
    }

    public String getIpAddress() throws IOException {
        InetAddress ownIP=InetAddress.getLocalHost();
        return ownIP.getHostAddress();
    }

    

    public boolean isLoginStatus() {
        return LoginStatus;
    }

    public int getUserId() {
        return UserId;
    }

    public void setUserId(int UserId) {
        this.UserId = UserId;
    }

    public String getUserName() {
        return UserName;
    }

    public void setUserName(String UserName) {
        this.UserName = UserName;
    }
    
}
